#ifndef xpack_define_base_type
#define xpack_define_base_type
    #include<stdint.h>

    using i08      = int8_t;
    using i16      = int16_t;
    using i32      = int32_t;
    using i64      = int64_t;
    using u08      = uint8_t;
    using u16      = uint16_t;
    using u32      = uint32_t;
    using u64      = uint64_t;
    using f32      = float;
    using f64      = double;
    using f80      = long double;
    using asciis   = const char *;
    using words    = const char16_t *;
    using ci08     = const i08;
    using ci16     = const i16;
    using ci32     = const i32;
    using ci64     = const i64;
    using cu08     = const u08;
    using cu16     = const u16;
    using cu32     = const u32;
    using cu64     = const u64;
    using cf32     = const f32;
    using cf64     = const f64;
    using i08p     = i08  *;
    using i16p     = i16  *;
    using i32p     = i32  *;
    using i64p     = i64  *;
    using u08p     = u08  *;
    using u16p     = u16  *;
    using u32p     = u32  *;
    using u64p     = u64  *;
    using f32p     = f32  *;
    using f64p     = f64  *;
    using w16p     = char16_t  *;
    using voidp    = void *;
    using byte     = u08;
    using ci08p    = const i08 *;
    using ci16p    = const i16 *;
    using ci32p    = const i32 *;
    using ci64p    = const i64 *;
    using cu08p    = const u08 *;
    using cu16p    = const u16 *;
    using cu32p    = const u32 *;
    using cu64p    = const u64 *;
    using cf32p    = const f32 *;
    using cf64p    = const f64 *;

    #ifndef size_t
        using size_t = decltype(sizeof(0));
        #define size_t      size_t
    #endif

    #define xbitsof(...)                    (sizeof(__VA_ARGS__) * 8)

    namespace mixc::base_type{
        template<int> struct env{};

        template<>
        struct env<4>{
            using ixx              = i32;
            using uxx              = u32;
            using thread_counter_t = u16;
        };

        template<>
        struct env<8>{
            using ixx              = i64;
            using uxx              = u64;
            using thread_counter_t = u32;
        };
    }

    struct u128{
        u64 low     = 0;
        u64 high    = 0;

        u128(){}
        u128(u64 low, u64 high) : 
            low(low), high(high){}

        auto & l(u64 value){
            low = value;
            return this[0];
        }

        auto & h(u64 value){
            high = value;
            return this[0];
        }
    };

    template<class type_t>
    struct quo_rem_pair{
        type_t quotient;
        type_t remainder;

        auto & q(type_t value){
            quotient = value;
            return this[0];
        }

        auto & r(type_t value){
            remainder = value;
            return this[0];
        }
    };

    using ixx               = mixc::base_type::env<sizeof(void *)>::ixx;
    using uxx               = mixc::base_type::env<sizeof(void *)>::uxx;
    using thread_counter_t  = mixc::base_type::env<sizeof(void *)>::thread_counter_t;
    using ixxp              = ixx *;
    using uxxp              = uxx *;

    // 使用 enum 而非 enum class，可以让返回值支持 and 截断操作
    // bstate_t result = operator0() and operator1();
    // 前一个操作失败了后边的操作就不会执行
    enum bstate_t : uxx{ // binary state
        fail,
        success,
    };

    enum class loop_t{
        finish,
        go_on,
    };

    struct zero_t{
        constexpr zero_t(){}

        operator uxx() const {
            return 0;
        }
    };

    template<auto i_v>
    struct binaray_option{
        constexpr explicit binaray_option(bool value) : value(value){}
        constexpr binaray_option<i_v> operator ! () const {
            return binaray_option<i_v>(not value);
        }
        operator bool() const {
            return value;
        }

    private:
        bool value = false;
    };

    template<auto i_v>
    struct just_flag{ constexpr just_flag(){} };

    template<class value_t, auto>
    union explicit_type{
        constexpr explicit explicit_type(value_t value) : value(value) { }
        constexpr operator value_t() const {
            return value;
        }

    private:
        value_t value;
    };

    template<auto>
    struct template_flag_wraper{
        enum class type_t{};
    };

    template<class enum_t>
    requires(__is_enum(enum_t))
    constexpr auto operator !(enum_t value){
        return enum_t(!(uxx)(value));
    }

    #define __xthe_counter0      (__COUNTER__ - __base_type_counter0)
    #define __xthe_counter1      (__COUNTER__ - __base_type_counter1)
    #define __xthe_counter2      (__COUNTER__ - __base_type_counter2)

    template<auto i_v>
    using template_flag         = typename template_flag_wraper<i_v>::type_t;

    enum{ __base_type_counter0 = __COUNTER__ + 1, };
    using need_free_t           = binaray_option<__xthe_counter0>;
    using need_initial_t        = binaray_option<__xthe_counter0>;
    using need_destruction_t    = binaray_option<__xthe_counter0>;
    using generic_option_t      = binaray_option<__xthe_counter0>;

    enum{ __base_type_counter1 = __COUNTER__ + 1, };
    using ignore_propcast_t     = template_flag<__xthe_counter1>;
    using vnull_t               = template_flag<__xthe_counter1>;
    using echo_t                = template_flag<__xthe_counter1>;
    using lock_free_t           = template_flag<__xthe_counter1>;

    enum{ __base_type_counter2 = __COUNTER__ + 1, };
    using length                = explicit_type<uxx, __xthe_counter2>;
    using handler               = explicit_type<ixx, __xthe_counter2>;

    constexpr uxx                   not_exist    = uxx(-1);
    constexpr uxx                   magic_number = 19961212;
    constexpr zero_t                zero{};
    constexpr need_free_t           need_free{ true };
    constexpr need_initial_t        need_initial{ true };
    constexpr need_destruction_t    need_destruction{ true };
    constexpr ignore_propcast_t     ignore_propcast{ true };
    constexpr ignore_propcast_t     with_propcast{ false }; // 负逻辑
    constexpr echo_t                echo{ true };
    constexpr lock_free_t           lock_free{ true };

    constexpr bool                  enable  = true;
    constexpr bool                  disable = false;

    constexpr bool                  yes     = true;
    constexpr bool                  no      = false;

    // 使用 union，避免 struct 类型的检查
    union secret_mark_t{
        constexpr secret_mark_t(){}

        #define __xsecret_mark(...)      __VA_ARGS__ ## "secret"
        operator asciis() const {
            return __xsecret_mark();
        }

        operator words() const {
            return __xsecret_mark(u);
        }

        #undef __xsecret_mark
    private:
        bool dummy = false; // 避免高版本 gcc12.3 编译错误，不允许空成员的 constexpr，这个 gcc 有点问题
    };

    constexpr secret_mark_t secret_mark;

    #if !__GNUC__
    #define not     !
    #define and     && 
    #define or      ||
    #endif

    #undef  __xthe_counter
#endif
